<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use chrome\ChromePhp;
use common\Common;
use uploadImg\UtilImage;
use app\common\model\store\LibStorePhone;
use app\common\model\store\LibCategory;
use app\common\model\UtilConfig;
/**
 *商城消息管理
 * @name store_storePhone.php
 * @package cws
 * @category controller
 * @link http://www.chanekeji.com
 * @author jeky
 * @version 2.0
 * @copyright CHANGE INC
 * @since 2016-09-01
 */
class StorePhone extends AdminController{
    private $lib_storePhone;
	/**
	 * 构造函数
	 */
	function __construct() {
		parent::__construct ();
		error_reporting ( E_ALL & ~ E_NOTICE & ~ E_DEPRECATED & ~ E_STRICT & ~ E_WARNING );
		$this->rightVerify(session('admin'), url("admin/Login/login"));
		$this->lib_storePhone = new LibStorePhone();
	}
	
	//--------------------------百货配置---------------------------------------
	/**
	 ** 商城消息列表页面
	 **/
	function storePhoneList(){
	    $this->getSetMenu($this);
	    //日志记录
        $this->log(__CLASS__, __FUNCTION__, "消息列表页面", 1, 'view');
		return $this->fetch("StoreStorePhone/storePhoneList/storePhoneList");
	}
   
   	/**
     * 添加商城消息
     */
    function addStorePhone(){
		$this->getMenu($this);
    	$this->log(__CLASS__, __FUNCTION__, "添加消息页面", 1, 'add');
		return $this->fetch("StoreStorePhone/addStorePhone/addStorePhone");
    }
	
	/**
	 * 编辑消息
	 */
	function editStorePhone(){
		$this->getMenu($this);
		$id = input('id');
		//查找消息
		$result = $this->lib_storePhone->findStorePhone(array('id'=>$id));
		$this->assign('storePhoneInfo',$result['data']);
		$this->log(__CLASS__, __FUNCTION__ ,"编辑消息页面",1,'edit');
		return $this->fetch("StoreStorePhone/editStorePhone/editStorePhone");
	} 
	
	
	/**
	 * 插入商城消息
	 */
	function insertStorePhone(){
		$storePhoneInfo = $this->getArgsList($this, array('title','link','sort'));
		$result = $this->lib_storePhone->addStorePhone($storePhoneInfo);
		$this->log(__CLASS__, __FUNCTION__ ,"插入商城消息",0,'add');
		
		echo json_encode($result);
	}
	
	/**
	 * 更新商城信息
	 */
	function updateStorePhone(){
		$storePhoneInfo = $this->getArgsList($this, array('title','link','sort'));
		$id = input('id');
		$conditions = array('id'=>$id);
		$result = $this->lib_storePhone->updateStorePhone($conditions,$storePhoneInfo);
		$this->log(__CLASS__, __FUNCTION__ ,"更新商城信息",0,'edit');
		
		echo json_encode($result);
	}
	
	/**
	 * 商城公告置顶
	 */
	function setTop(){
		$storePhoneInfo = $this->getArgsList($this, array());
		$id = input('id');
		$conditions = array('id'=>$id);
		$storePhoneInfo['top_time'] = Common::getTime();
		$result = $this->lib_storePhone->updateStorePhone($conditions,$storePhoneInfo);
		$this->log(__CLASS__, __FUNCTION__ ,"商城信息置顶",0,'setTop');
		
		echo json_encode($result);
	}
	
	/**
	 * 删除消息
	 */
	function deleteStorePhone(){
		$id = input('id');
		$conditions = array('id'=>$id);
		$result = $this->lib_storePhone->deleteStorePhone($conditions);
		$this->log(__CLASS__, __FUNCTION__ ,"删除消息",0,'del');
		
		echo json_encode($result);
	}
	
	/**
	 * 批量删除商品
	 */
	function batchDeleteStorePhone(){
		$gids = input('ids');
		$result = $this->lib_storePhone->batchDeleteStorePhone($gids);
		$this->log(__CLASS__, __FUNCTION__, "批量删除商品", 0, 'del');
		echo json_encode($result);
	}
	
	/**
	 * 分页查询商城消息
	 */
	function pagingStorePhone(){
		$page = $this->getPageInfo($this);
		$sort ="top_time desc";
		$conditionList = $this->getPagingList($this, array('title' => 'like'));
		$result = $this->lib_storePhone->pagingStorePhone( $page, $conditionList, $sort);
		$this->log(__CLASS__, __FUNCTION__ ,"pagingStorePhone",0,'view');
		
		echo json_encode($result);
	}
}